//
//  PersonVC.swift
//  gungunchou
//
//  Created by ljjxj on 2019/9/2.
//  Copyright © 2019 xskj. All rights reserved.
//

import UIKit

class PersonVC: UIViewController {
    let listArr = ["我的订单", "清除缓存", "关于我们"]
    @IBOutlet weak var table: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.setupViews()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(true, animated: false)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: false)
    }
    
    func setupViews() -> (){
        
        table.register(UINib.init(nibName: "PersonItemCell", bundle: nil), forCellReuseIdentifier: "PersonItemCell")
    
        let tableHead = UIView.init(frame: CGRect.init(x: 0, y: 0, width: Screen_W, height: 200))
        let headContentV = Bundle.main.loadNibNamed("PersonHeader", owner: nil, options: nil)?.first as!PersonHeader
        
        tableHead.addSubview(headContentV)
        headContentV.mas_remakeConstraints { (make) in
            make?.edges.offset()(0)
        }
        table.tableHeaderView = tableHead
        
        let tableFoot = UIView.init(frame: CGRect.init(x: 0, y: 0, width: Screen_W, height: 70))
        let footBtn = UIButton.init(type: .custom)
        footBtn.setTitle("退出登录", for: .normal)
        footBtn.setTitleColor(.red, for: .normal)
        footBtn.backgroundColor = .white
        footBtn.addTarget(self, action: #selector(logoutClick), for: .touchUpInside)
        
        tableFoot.addSubview(footBtn)
        footBtn.mas_remakeConstraints { (make) in
            make?.edges.equalTo()(tableFoot)?.with()?.insets()(UIEdgeInsets.init(top: 20, left: 0, bottom: 0, right: 0))
        }
        table.tableFooterView = tableFoot
    }
    
    @objc func logoutClick() {
        
    }
}

extension PersonVC : UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "PersonItemCell", for: indexPath) as!PersonItemCell
        cell.nameLbl.text = listArr[indexPath.row];
        return cell
    }
    
}
